package georah.map.graphics
{

	import mx.core.UIComponent;
	import mx.graphics.RectangularDropShadow;

	/**
	 *
	 * @author yuanm
	 */
	public final class InfoMarker extends MapGraphic
	{
		public var backgroundAlpha:Number=1;

		public var backgroundColor:int=0xffffff;

		public var borderAlpha:Number=0.5;

		public var borderColor:int=0x000000;

		public var borderThickness:int=0;

		private var _dropShadow:RectangularDropShadow=new RectangularDropShadow();

		private var _footSize:Number=10;

		private var _infoContent:UIComponent=new UIComponent();

		private var _padding:Number=4;

		override public function clone():MapGraphic
		{
			var m:InfoMarker=new InfoMarker();
			m.width=width;
			m.height=height;
			m.backgroundAlpha=backgroundAlpha;
			m.backgroundColor=backgroundColor;
			m.borderAlpha=borderAlpha;
			m.borderColor=borderColor;
			m.borderThickness=borderThickness;
			m.content=content;
			m.footSize=footSize;
			m.padding=padding;
			return m;
		}

		public final function get content():UIComponent
		{
			return _infoContent;
		}

		public final function set content(value:UIComponent):void
		{
			_infoContent=value;
		}

		public final function get footSize():Number
		{
			return _footSize;
		}

		public final function set footSize(value:Number):void
		{
			_footSize=value;
		}

		public final function get padding():Number
		{
			return _padding;
		}

		public final function set padding(value:Number):void
		{
			_padding=value;
		}

		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth, unscaledHeight);

			container.x=-0.5 * unscaledWidth;
			container.y=-unscaledHeight;

			container.graphics.clear();
			_dropShadow.drawShadow(container.graphics, 0, 0, unscaledWidth - _dropShadow.distance, unscaledHeight - _footSize - _dropShadow.distance);
			container.graphics.lineStyle(borderThickness, borderColor, borderAlpha);
			container.graphics.beginFill(backgroundColor, backgroundAlpha);
			container.graphics.moveTo(0, 0);
			container.graphics.lineTo(unscaledWidth - _dropShadow.distance, 0);
			container.graphics.lineTo(unscaledWidth - _dropShadow.distance, unscaledHeight - _footSize - _dropShadow.distance);
			container.graphics.lineTo(unscaledWidth / 2 + _footSize / 2 + 0.5 * _dropShadow.distance, unscaledHeight - _footSize - _dropShadow.distance);
			container.graphics.lineTo(unscaledWidth / 2, unscaledHeight);
			container.graphics.lineTo(unscaledWidth / 2 - _footSize / 2 - 0.5 * _dropShadow.distance, unscaledHeight - _footSize - _dropShadow.distance);
			container.graphics.lineTo(0, unscaledHeight - _footSize - _dropShadow.distance);
			container.graphics.lineTo(0, 0);
			container.graphics.endFill();

			if (!container.contains(_infoContent))
			{
				container.addChild(_infoContent);
			}

			_infoContent.x=padding;
			_infoContent.y=padding;
			_infoContent.width=unscaledWidth - _dropShadow.distance - 2 * padding;
			_infoContent.height=unscaledHeight - _footSize - _dropShadow.distance - 2 * padding;
		}

	}
}